﻿using System.Windows;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using TimeSpan.Views.Pages;
using TimeSpan.Views.Windows;

namespace TimeSpan.Services;

internal class ApplicationHostService(IServiceProvider serviceProvider) : IHostedService {

    public async Task StartAsync(CancellationToken cancellationToken) {
        if (!Application.Current.Windows.OfType<MainWindow>().Any()) {
            var navigationWindow = serviceProvider.GetRequiredService<MainWindow>();
            navigationWindow.Show();

            var navigationService = serviceProvider.GetRequiredService<INavigationService>();
            navigationService.Navigate<HomePage>();
        }

        await Task.CompletedTask;
    }

    public async Task StopAsync(CancellationToken cancellationToken) {
        await Task.CompletedTask;
    }
}